﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonWFLibrary;
using System.IO;
using System.Configuration;

namespace DeepTalkRenderService.Services
{
    /// <summary>
    /// Make sure info associated with the long running activities is correctly written out to disk!
    /// </summary>
    public class DTLongRunningPersistance : LongRunningActivityBaseService
	{
        /// <summary>
        /// Returns a file that can be used to save the long running activity info.
        /// </summary>
        /// <returns></returns>
        private static FileInfo GetFileInfo()
        {
            string pdir = ConfigurationManager.AppSettings["PersitanceDirectory"];
            return new FileInfo(pdir + "\\longRunningActivityInfo.bin");
        }

        /// <summary>
        /// Static dude that deals with the i/o - a way of hiding things...
        /// </summary>
        private static LongRunningActivityBinaryPersister lrp = new LongRunningActivityBinaryPersister(GetFileInfo());

        /// <summary>
        /// Create the service, and attach everything we need to do the i/o.
        /// </summary>
        public DTLongRunningPersistance()
            : base(obj => lrp.Save(obj), () => lrp.Restore())
        {
        }
	}
}
